/*** 本文件由CSMIS2.0-ModelCreater(UTF-8)工具辅助生成，版本1.0 ***/

package com.ce.sys.log.logic.search;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.datamaintain.logic.SQLSearchCondition;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.StringUtil;
import com.ce.sys.log.view.SysUserOperateLogView;

/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2010-11-25
* 创建时间：09:27:44
* 功能描述： [SYS_T_USER_OPERATE_LOG]条件过滤类
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class SysUserOperateLogSearchCondition  extends SQLSearchCondition
	implements ISQLMapper
{

	/*
	 * 使用js框架分页时进行排序的必要属性
	 */
	private String order;   //排序方法
	private String sort;  //排序字段
	private String month;  //年份
	private String year;   //月份
	private String user;   //用户
	private String funname; //菜单名称
	private String module; //菜单名称
	private String opdate;  //操作日期
	private String ip;     //访问ip


	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}


	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getSearchSql() throws AppException {
		if(StringUtil.isNotBlank(opdate)){
			this.year = opdate.split("-")[0];
			this.month = opdate.split("-")[1];
		}
		if(StringUtil.isNotBlank(month)&&month.length()<=1){
			month = "0"+month;
		}
		StringBuffer sql = new StringBuffer("select * from SYS_T_USER_OPERATE_LOG_"+year+"_"+month+" t where VC_DEL$FLAG = 0");
		if(StringUtil.isNotBlank(user)){
			sql.append(" and t.VC_OPERATOR like '%"+this.getSafeValue(this.user)+"%' ");
		}
		if(StringUtil.isNotBlank(funname)){
			sql.append(" and t.VC_FUNNAME like '%"+this.getSafeValue(this.funname)+"%' ");
		}
		if(StringUtil.isNotBlank(module)){
			sql.append(" and t.VC_MODULE like '%"+this.getSafeValue(this.module)+"%' ");
		}
		if(StringUtil.isNotBlank(ip)){
			sql.append(" and t.VC_IP_ADDR like '%"+this.getSafeValue(this.ip)+"%' ");
		}
		if(StringUtil.isNotBlank(opdate)){
			sql.append("  and to_char(t.DT_TIME,'yyyy-MM-dd') ='"+this.getSafeValue(opdate)+"' ");
		}
		
		//实现排序的代码
		if(StringUtil.isNotBlank(this.order)){
			if("vcFunname".equals(this.sort)){
				sql.append("  order by t.VC_FUNNAME "+this.order);
			}	
			if("VC_MODULE".equals(this.sort)){
				sql.append("  order by t.VC_MODULE "+this.order);
			}	
			if("vcUrl".equals(this.sort)){
				sql.append("  order by t.VC_URL "+this.order);
			}	
			if("dtTime".equals(this.sort)){
				sql.append("  order by t.DT_TIME "+this.order);
			}	
			if("vcOperator".equals(this.sort)){
				sql.append("  order by t.VC_OPERATOR "+this.order);
			}	
			if("vcIpAddr".equals(this.sort)){
				sql.append("  order by t.VC_IP_ADDR "+this.order);
			}	
		}else{
			sql.append("  order by t.DT_TIME desc ");
		}
		return sql.toString();
	}
	
	public Object fromSQLQuery(ResultSet rs, int num) {
		SysUserOperateLogView view = new SysUserOperateLogView();
		try {

			view.setVcId(rs.getString("VC_ID"));
			view.setVcUrl(rs.getString("VC_URL"));
			view.setVcFunname(rs.getString("VC_FUNNAME"));
			view.setVcOperate(rs.getString("VC_OPERATE"));
			view.setDtTime(rs.getTimestamp("DT_TIME"));
			view.setVcOperator(rs.getString("VC_OPERATOR"));
			view.setVcIpAddr(rs.getString("VC_IP_ADDR"));
			view.setVcDelFlag(rs.getInt("VC_DEL$FLAG"));
			view.setVcNote(rs.getString("VC_NOTE"));
			view.setVcModule(rs.getString("VC_MODULE"));			

		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return view;
	}
	
	public ISQLMapper getSQLMapper() {
		
		return this;
	}

	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
	}

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getFunname() {
		return funname;
	}

	public void setFunname(String funname) {
		this.funname = funname;
	}

	public String getOpdate() {
		return opdate;
	}

	public void setOpdate(String opdate) {
		this.opdate = opdate;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getModule() {
		return module;
	}

	public void setModule(String module) {
		this.module = module;
	}

}

